//
//  ZhuCeViewController.m
//  ShangChengMoBan
//
//  Created by yaoqi yaoqi on 16/9/10.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "ZhuCeViewController.h"
#import "YanZhengMaBtn.h"
@interface ZhuCeViewController ()<UITextFieldDelegate,YanZhengMaBtnDelegate>
@property (weak, nonatomic) IBOutlet UITextField *name;
@property (weak, nonatomic) IBOutlet UITextField *shouJi;
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UITextField *yanZhengMa;
@property (weak, nonatomic) IBOutlet UILabel *xieYi;

@property (nonatomic, strong)YanZhengMaBtn *huoQu;
@property (weak, nonatomic) IBOutlet UITextField *miMa;
@property (weak, nonatomic) IBOutlet UIButton *zhuCe;


- (IBAction)ZhuCe:(id)sender;


@property (weak, nonatomic) IBOutlet UITextField *miMa2;

@end

@implementation ZhuCeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawNavWithTitle:@"注册" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
    [self drawBackButton];
    self.view.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.00 brightness:0.92 alpha:1.00];
    UIView * view = [[[NSBundle mainBundle]loadNibNamed:@"ZhuCe" owner:self options:nil]lastObject];
    
    view.frame = CGRectMake(0, 64, KScreenWidth, 324+42);
    [self.view addSubview:view];
    _zhuCe.layer.cornerRadius = 4;
    //初始化按钮
    _huoQu = [[YanZhengMaBtn alloc]initWithFrame:CGRectMake(KScreenWidth-110,10,100, 30)];
    _huoQu.backgroundColor = [UIColor colorWithHue:0.00 saturation:0.93 brightness:1.00 alpha:1.00];
    _huoQu.DaoJiShitime = 60;
    _huoQu.againColor = [UIColor orangeColor];
    _huoQu.delegate = self;
    _huoQu.layer.cornerRadius = 15;
    [_huoQu setTitle:@"发送验证码" forState:UIControlStateNormal];
    _huoQu.titleLabel.font = [UIFont systemFontOfSize:14];
    [_view1 addSubview:_huoQu];
     NSMutableAttributedString * abs = [[NSMutableAttributedString alloc]initWithString:@"我已阅读并同意《商城用户协议》"];
    [abs addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHue:1.00 saturation:1.00 brightness:1.00 alpha:1.00] range:NSMakeRange(7, 8)];
    _xieYi.attributedText = abs;
  }
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    if([textField isEqual:_shouJi]){
        [_yanZhengMa becomeFirstResponder];
    }else if([textField isEqual:_yanZhengMa]){
          [_miMa2 becomeFirstResponder];
    }else if([textField isEqual:_miMa2]){
        [_miMa becomeFirstResponder];
    }else{
      [textField endEditing:YES];
    }
    return YES;
}

#pragma mark 注册
- (IBAction)ZhuCe:(id)sender {
    if (_yanZhengMa.text.length == 0 || _shouJi.text.length == 0 || _miMa.text.length == 0|| _miMa2.text.length == 0 || _name.text.length == 0) {
        [[iToast makeText:@"  请完善信息!  "] show];
        return;
    }
    if (![_miMa.text isEqualToString:_miMa2.text]) {
        [[iToast makeText:@"  两次密码不匹配!  "] show];
        return;
    }
    NSMutableDictionary *requestDictionary = [NSMutableDictionary dictionary];
    [requestDictionary setObject:_name.text forKey:@"userName"];
    [requestDictionary setObject:_shouJi.text forKey:@"phone"];
    [requestDictionary setObject:_miMa.text forKey:@"twopassword"];
    [requestDictionary setObject:_miMa2.text forKey:@"password"];
    [requestDictionary setObject:_yanZhengMa.text forKey:@"code"];
    
    [NetWorking NEWjieKouQingQiu:ZC_zhuCeMain ANDIP:IP And:requestDictionary anBlock:^(NSDictionary *dic, NSError *error) {
        if (!error) {
            if ([[dic objectForKey:Code]integerValue] == 200) {
                [TCUtils showAlertViewWithTitle:@"提示" message:@"注册成功" delegate:nil cancel:@"确定" other:nil tag:0];
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
    }];

    
}

#pragma mark 获取验证码
-(void)sendYanZhengMa{
    [_huoQu daoJiShi];
    [NetWorking NEWjieKouQingQiu:YZM_yanZhengMain ANDIP:IP And:@{@"phone":_shouJi.text} anBlock:^(NSDictionary *dic, NSError *error) {
        if (!error) {
            if ([[dic objectForKey:Code]integerValue] == 200) {
                
            }
        }
    }];

}

@end
